package com.yaosheng.thread.app;

import java.util.Vector;
import java.util.concurrent.TimeUnit;

/**
 * Created by yaosheng on 2021/7/5.
 */
public class TickerSeller3 {

    static Vector<String> tickets = new Vector<> ();

    static {
        for (int i = 0;i < 1000;i ++){
            tickets.add ("车票编号:" + i);
        }
    }

    public static void main(String[] args) {

        for(int i = 0;i < 10;i ++){
            new Thread ( () -> {
                while (true){
                    synchronized (tickets){
                        if(tickets.size () <= 0) break;
                        try{
                            TimeUnit.SECONDS.sleep (1);
                        } catch (InterruptedException e) {
                            e.printStackTrace ();
                        }
                        System.out.println ("销售了--" + tickets.remove (0));
                    }
                }
            }).start ();
        }
    }
}
